//
//  DDJobsService.m
//  DingDongZP
//
//  Created by Jyh on 16/3/22.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDJobsService.h"

@implementation DDJobsService

- (void)queryJobsWithPage:(NSString *)page
             successBlock:(successBlock)successBlock
                failBlock:(faileBlock)failBlock
{

    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobs"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (page) {
        params[@"page"] = page;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager GET:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)queryRecommendJobsWithPage:(NSString *)page jobID:(NSString *)jobid
                      successBlock:(successBlock)successBlock
                         failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_discover_jobs_match"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (page) {
        params[@"page"] = page;
    }
    
    if (jobid) {
        params[@"job_id"] = jobid;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)queryHotestOrLatestJobsWithPage:(NSString *)page
                                  order:(NSString *)order
                           successBlock:(successBlock)successBlock
                              failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_discover_jobs_order"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (page) {
        params[@"page"] = page;
    }
    if (order) {
        params[@"order"] = order;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)queryJobsWithJobId:(NSString *)jobId
                Filtertype:(NSString *)filtertype
                  FilterID:(NSString *)filterId
                      page:(NSString *)page
              SuccessBlock:(successBlock)successBlock
                 failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_discover_jobs_filter"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (jobId) {
        params[@"job_id"] = jobId;
    }
    if (filtertype) {
        params[@"filtertype"] = filtertype;
    }
    if (filterId) {
        params[@"filterid"] = filterId;
    }
    if (page) {
        params[@"page"] = page;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

//请求工作详情 未登录状态
- (void)queryNoLoginJobsDetailWithJobId:(NSString *)jobid
                           successBlock:(successBlock)successBlock
                              failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_notloggedin_view_job"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (jobid) {
        params[@"job_id"] = jobid;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager GET:URLString parameters:params success:successBlock failure:failBlock];
}

//请求工作详情 登录状态
- (void)queryLoginJobsDetailWithJobId:(NSString *)jobid
                         successBlock:(successBlock)successBlock
                            failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_loggedin_view_job"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (jobid) {
        params[@"job_id"] = jobid;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}


- (void)queryInterestedJobWithJobId:(NSString *)jobid
                       successBlock:(successBlock)successBlock
                          failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_query_interestedjob"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (jobid) {
        params[@"jobid"] = jobid;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)markInterestingJobWithJobId:(NSString *)jobid
                       successBlock:(successBlock)successBlock
                          failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_toggle_interestedjob"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (jobid) {
        params[@"jobid"] = jobid;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)queryMyselfResumeSuccessBlock:(successBlock)successBlock
                            failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_query_userinfo"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)setMyselfCurrentExpectJobId:(NSString *)expectJobID
                       successBlock:(successBlock)successBlock
                          failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_set_current_expectedjob"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (expectJobID) {
        params[@"expectjob_id"] = expectJobID;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)queryJobfindersAdsArray:(void (^)(NSArray *ads))callback
{
    NSString *requestUrlString = [[DDAPIGenerate sharedInstance] API:@"query_ads_jobfinders"];
    
    [[DDNetWorkManager shareManager] GET:requestUrlString parameters:nil success:^(id responseObject) {
        NSInteger success = [responseObject[@"code"] integerValue];
        if (success) {
            NSArray *resultArray = responseObject[@"data"];
            if (resultArray) {
                callback(resultArray);
            } else {
                callback(nil);
            }
        } else {
            callback(nil);
        }
        
    } failure:^(id responseObject, NSError *error) {
        callback(nil);
    }];
}

- (void)reportBossWithBossId:(NSString *)bossid
                    reportId:(NSString *)reportId
                successBlock:(successBlock)successBlock
                   failBlock:(faileBlock)failBlock
{

    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_complain_about_employer"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (bossid) {
        params[@"employer_id"] = bossid;
    }
    
    if (reportId) {
        params[@"complaint_id"] = reportId;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager POST:URLString parameters:params success:successBlock failure:failBlock];
}

- (void)queryBossPublishedJobsWithBossID:(NSString *)bossId
                                    page:(NSString *)page
                            successBlock:(successBlock)successBlock
                               failBlock:(faileBlock)failBlock
{
    NSString *URLString = [[DDAPIGenerate sharedInstance] API:@"jobfinder_query_employerjobs"];
    
    NSMutableDictionary *params = [@{} mutableCopy];
    
    if (bossId) {
        params[@"employer_id"] = bossId;
    }
    if (page) {
        params[@"page"] = page;
    }
    
    DDNetWorkManager *manager = [DDNetWorkManager shareManager];
    
    [manager GET:URLString parameters:params success:successBlock failure:failBlock];
}

@end
